﻿namespace UnityEditor
{
    using System;
    using UnityEngine;

    internal class PingData
    {
        public float m_AvailableWidth = 100f;
        public GUIContent m_Content = new GUIContent();
        public Vector2 m_ContentTopLeft = new Vector2();
        public float m_FadeOutTime = 1.5f;
        public FontStyle m_FontStyle;
        public float m_PeakScale = 1.75f;
        public GUIStyle m_PingStyle = new GUIStyle();
        public float m_TimeStart = -1f;
        public float m_WaitTime = 2.5f;
        public float m_ZoomTime = 0.2f;

        public void HandlePing()
        {
            if (this.isPinging)
            {
                float num = (this.m_ZoomTime + this.m_WaitTime) + this.m_FadeOutTime;
                float num2 = Time.realtimeSinceStartup - this.m_TimeStart;
                if ((num2 > 0f) && (num2 < num))
                {
                    Color color = GUI.color;
                    Matrix4x4 matrix = GUI.matrix;
                    FontStyle fontStyle = this.m_PingStyle.fontStyle;
                    this.m_PingStyle.fontStyle = this.m_FontStyle;
                    Vector2 vector = this.m_PingStyle.CalcSize(this.m_Content);
                    vector = new Vector2(vector.x, this.m_PingStyle.CalcHeight(this.m_Content, vector.x));
                    Rect position = new Rect(this.m_ContentTopLeft.x - this.m_PingStyle.padding.left, this.m_ContentTopLeft.y - this.m_PingStyle.padding.top, vector.x, vector.y);
                    if (num2 < this.m_ZoomTime)
                    {
                        float num3 = this.m_ZoomTime / 2f;
                        float x = ((this.m_PeakScale - 1f) * (((this.m_ZoomTime - Mathf.Abs((float) (num3 - num2))) / num3) - 1f)) + 1f;
                        Matrix4x4 matrixx2 = GUI.matrix;
                        Vector2 pos = (position.xMax >= this.m_AvailableWidth) ? new Vector2(this.m_AvailableWidth, position.center.y) : position.center;
                        Vector2 vector3 = GUIClip.Unclip(pos);
                        Matrix4x4 matrixx3 = Matrix4x4.TRS((Vector3) vector3, Quaternion.identity, new Vector3(x, x, 1f)) * Matrix4x4.TRS((Vector3) -vector3, Quaternion.identity, Vector3.one);
                        GUI.matrix = matrixx3 * matrixx2;
                    }
                    else if (num2 > (this.m_ZoomTime + this.m_WaitTime))
                    {
                        float num5 = (num - num2) / this.m_FadeOutTime;
                        GUI.color = new Color(color.r, color.g, color.b, color.a * num5);
                    }
                    if ((this.m_Content != null) && (Event.current.type == EventType.Repaint))
                    {
                        this.m_PingStyle.Draw(position, this.m_Content, false, false, false, false);
                    }
                    this.m_PingStyle.fontStyle = fontStyle;
                    GUI.matrix = matrix;
                    GUI.color = color;
                }
                else
                {
                    this.m_TimeStart = -1f;
                }
            }
        }

        public bool isPinging
        {
            get
            {
                return (this.m_TimeStart > -1f);
            }
        }
    }
}

